package com.kfit.java8.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test3 {
	public static void main(String[] args) {
		
		//1.1 去空
		List<String> list = Arrays.asList("悟空","","唐僧","八戒","悟净","白龙马");
		List<String> newList = list.stream().filter(str->!str.isEmpty()).collect(Collectors.toList());
		//结果：newList=("悟空","唐僧","八戒","悟净","白龙马")
		newList.forEach(System.out::println);
		
		
		
		Integer [] nums = {1, 2, 3, 4, 5, 6};
		Integer[] evenNums = Stream.of(nums).filter(n->n%2==0).toArray(Integer[]::new);
		//结果：evenNums=[2, 4, 6]
		System.out.println(Arrays.toString(evenNums));
		
		long count = Stream.of(nums).filter(n->n%2==0).count();
		//结果：count=3
		System.out.println(count);
		
		//1.2 distinct ()：返回集合中各异的元素集合(去重)
		Integer[] numbers = {5, 1, 2, 1, 3, 3, 2, 4};
		Integer[] newNumbers = Arrays.stream(numbers).distinct().toArray(Integer[]::new);
		//结果：newNumbers =  [5, 1, 2, 3, 4]
		System.out.println(Arrays.toString(newNumbers));
	}
}
